<?php
/*
Extension Name: Better BB Code
Extension Url: http://lussumo.com/community/discussion/2161
Description: A BBCode-to-HTML conversion tool for discussion comments
Version: 1.0
Author: Joel Bernstein
Author Url: http://pong.uwstout.edu/
*/

require_once('BBCodeParser.php');

class BetterBBCodeFormatter extends StringFormatter
{

   function Parse($String, $Object, $FormatPurpose)
   {
      $parser = new HTML_BBCodeParser();

      if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY)
      {
         $String = $this->ProtectString($String);
         return $parser->qparse($String);
      }
      else
         return $String;
   }

   function ProtectString ($String) {
      $String = str_replace("<", "&lt;", $String);
      $String = str_replace("\r\n", "<br />", $String);
      return $String;
   }

}
// Instantiate the bbcode object and add it to the string manipulation methods
$BetterBBCodeFormatter = $Context->ObjectFactory->NewObject($Context, "BetterBBCodeFormatter");
$Context->StringManipulator->AddManipulator("BBCode", $BetterBBCodeFormatter);
?>